import { modal } from 'vue-strap'
import extend from 'extend'
import { showMsg, updateHualin } from '../../../../vuex/action'

const validation = {
  ac(data) {
    for (let name in data) {
      if ((data[name] + '').length === 0) {
        return '* 标记的均为必填/必选项'
      }
    }
    return true
  }
}

export default {
  name: 'hualin-configure',
  components: {
    'vue-modal': modal
  },
  props: ['showConfigure', 'ac', 'title'],
  data() {
    return {

    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xUpdateAc: updateHualin
    }
  },
  ready() {},
  methods: {
    submit() {
      var ac = extend(true, {}, this.ac)
      var valid = validation.ac(ac)
      if (valid !== true) {
        return this.xShowMsg({
          type: 'danger',
          content: valid
        })
      }
      this.xUpdateAc({
        phone: ac.phone,
        status: ac.status
      })
        .then(() => {
          this.showConfigure = false
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}